// Copyright (C) 2024 Kumo inc.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <thread>
#include <sstream>
#include <kllm/core/params.h>
#include <kmfs/filesystem.hpp>

namespace kllm {

    void KMParams::verify_model_alias() {
        if (model_alias == "unknown") {
            kumo::filesystem::path mpath(model);
            model_alias = mpath.filename().string();
        }
    }
    std::string common_params_get_system_info(const KMParams & params) {
        std::ostringstream os;

        os << "system_info: n_threads = " << params.cpuparams.n_threads;
        if (params.cpuparams_batch.n_threads != -1) {
            os << " (n_threads_batch = " << params.cpuparams_batch.n_threads << ")";
        }
#if defined(_WIN32) && (_WIN32_WINNT >= 0x0601) && !defined(__MINGW64__) // windows 7 and later
        // TODO: windows + arm64 + mingw64
    DWORD logicalProcessorCount = GetActiveProcessorCount(ALL_PROCESSOR_GROUPS);
    os << " / " << logicalProcessorCount << " | " << llama_print_system_info();
#else
        os << " / " << std::thread::hardware_concurrency() << " | " << llama_print_system_info();
#endif

        return os.str();
    }
}